package com.ecoolex.ying.space.job.scheduler;

import com.ecoolex.framework.common.util.Check;
import com.ecoolex.framework.scheduler.Job;
import com.ecoolex.framework.scheduler.JobComponent;
import com.ecoolex.framework.scheduler.JobRunningContext;
import com.ecoolex.ying.space.core.manager.UserGoodsAttachmentDownloadTaskManager;
import com.ecoolex.ying.space.entity.UserGoodsAttachmentDownloadTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;


@JobComponent
public class UserGoodsAttachmentDownloadTaskJob {

    private Logger log = LoggerFactory.getLogger(UserGoodsAttachmentDownloadTaskJob.class);

    @Autowired
    private UserGoodsAttachmentDownloadTaskManager userGoodsAttachmentDownloadTaskManager;

    @Job(name = "ying.space.UserGoodsAttachmentDownloadTaskJob.download", describe = "用户商品附件下载任务")
    public void process(JobRunningContext context) {
        for (int i = 0; i <= 10; i++) {
            UserGoodsAttachmentDownloadTask task = userGoodsAttachmentDownloadTaskManager.getUntreated();
            if (Check.isNull(task)) {
                break;
            }
            userGoodsAttachmentDownloadTaskManager.processing(task, this.getClass().getSimpleName());
        }
    }
}